from PyQt6.QtWidgets import (
    QWidget, QVBoxLayout, QHBoxLayout, QPushButton, QLabel, 
    QGroupBox, QGridLayout
)
from PyQt6.QtGui import QFont
from PyQt6.QtCore import Qt

class LayoutsTab:
    """布局管理标签页"""
    
    def create_tab(self):
        """创建布局管理标签页"""
        tab = QWidget()
        layout = QVBoxLayout(tab)
        
        title = QLabel("PyQt6 布局管理")
        title.setFont(QFont("Arial", 16, QFont.Weight.Bold))
        title.setAlignment(Qt.AlignmentFlag.AlignCenter)
        layout.addWidget(title)
        
        # 水平布局示例
        hbox_group = QGroupBox("水平布局 (QHBoxLayout)")
        hbox_layout = QHBoxLayout(hbox_group)
        
        for i in range(1, 6):
            btn = QPushButton(f"按钮 {i}")
            hbox_layout.addWidget(btn)
        
        layout.addWidget(hbox_group)
        
        # 垂直布局示例
        vbox_group = QGroupBox("垂直布局 (QVBoxLayout)")
        vbox_layout = QVBoxLayout(vbox_group)
        
        for i in range(1, 6):
            btn = QPushButton(f"按钮 {i}")
            vbox_layout.addWidget(btn)
        
        layout.addWidget(vbox_group)
        
        # 网格布局示例
        grid_group = QGroupBox("网格布局 (QGridLayout)")
        grid_widget = QWidget()
        grid_layout = QGridLayout(grid_widget)
        
        positions = [(i, j) for i in range(3) for j in range(3)]
        for position in positions:
            row, col = position
            btn = QPushButton(f"{row},{col}")
            grid_layout.addWidget(btn, row, col)
        
        grid_group.setLayout(QVBoxLayout())
        grid_group.layout().addWidget(grid_widget)
        layout.addWidget(grid_group)
        
        # 嵌套布局示例
        nested_group = QGroupBox("嵌套布局示例")
        main_nested_layout = QHBoxLayout(nested_group)
        
        left_side = QVBoxLayout()
        left_side.addWidget(QLabel("左侧区域"))
        left_side.addWidget(QPushButton("按钮1"))
        left_side.addWidget(QPushButton("按钮2"))
        
        right_side = QGridLayout()
        right_side.addWidget(QLabel("右上"), 0, 0)
        right_side.addWidget(QPushButton("按钮3"), 0, 1)
        right_side.addWidget(QLabel("右下"), 1, 0, 1, 2)
        
        main_nested_layout.addLayout(left_side)
        main_nested_layout.addLayout(right_side)
        layout.addWidget(nested_group)
        
        return tab